const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('prescription', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true
    },
    prescription_number: {
      type: DataTypes.CHAR(50),
      allowNull: false
    },
    doctor: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      references: {
        model: 'user',
        key: 'id'
      }
    },
    patient: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      references: {
        model: 'patient',
        key: 'id'
      }
    },
    diagnose_date: {
      type: DataTypes.DATE,
      allowNull: false
    },
    diagnose_sort_id: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: true,
      references: {
        model: 'diagnose',
        key: 'id'
      }
    },
    diagnose_result: {
      type: DataTypes.TEXT,
      allowNull: true
    },
    transfusion: {
      type: DataTypes.BOOLEAN,
      allowNull: false
    },
    flesh: {
      type: DataTypes.BOOLEAN,
      allowNull: false
    },
    change_drug: {
      type: DataTypes.BOOLEAN,
      allowNull: false
    },
    cure: {
      type: DataTypes.BOOLEAN,
      allowNull: false
    },
    get_drug: {
      type: DataTypes.BOOLEAN,
      allowNull: false
    },
    cure_fee: {
      type: DataTypes.DOUBLE,
      allowNull: false
    },
    memo: {
      type: DataTypes.TEXT,
      allowNull: true
    }
  }, {
    sequelize,
    tableName: 'prescription',
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
      {
        name: "FK_prescription_doctor",
        using: "BTREE",
        fields: [
          { name: "doctor" },
        ]
      },
      {
        name: "FK_prescription_patient",
        using: "BTREE",
        fields: [
          { name: "patient" },
        ]
      },
      {
        name: "FK_prescription_diagnose_sort_id",
        using: "BTREE",
        fields: [
          { name: "diagnose_sort_id" },
        ]
      },
    ]
  });
};
